using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;

/// <summary>
/// Summary description for Email
/// </summary>
public class Email
{
    protected SmtpClient m_smtp = new SmtpClient();
    const String STANDARD_HTML_HEADER = "<html><head></head><body><table width='100%' border='0'><tr><td colspan='3'>header</td></tr>" +
                                            "<tr><td>LEFT</td><td>";

    const String STANDARD_HTML_FOOTER = "</td><td>RIGHT</td></tr>" +
                                            "<tr><td colspan='3'>FOOTER</td></tr></table>";

    String m_smtpHost = ""; // load host fom app.config

    public enum MailType
    {
        PLAINT_TEXT = 1,
        HTML = 2
    }

	public Email()
	{
		//
		// TODO: Add constructor logic here
		//
        m_smtp.Host = "pasmtp.tele.dk";
	}

    public void sendMail(String from, String to, String bcc, String subject, String body, MailType mtype, MailPriority importance)
    {
        try
        {
            MailMessage m = new MailMessage();
            m.From = new MailAddress(from);
            m.To.Add(new MailAddress(to));
            m.Bcc.Add(new MailAddress(bcc));
            m.IsBodyHtml = (mtype == MailType.HTML);
            m.Priority = importance;
            m.Subject = subject;
            m.Body = body;
            m_smtp.Send(m);
        }
        catch (Exception e)
        {
            throw e;
        }
    }

    public void sendTemplate(String from, String to, String bcc, String subject, String htmlBody, MailPriority importance)
    {
        try
        {
            MailMessage m = new MailMessage();
            m.From = new MailAddress(from);
            m.To.Add(new MailAddress(to));
            m.Bcc.Add(new MailAddress(bcc));
            m.IsBodyHtml = true;
            m.Priority = importance;
            m.Subject = subject;
            m.Body = STANDARD_HTML_HEADER + htmlBody + STANDARD_HTML_FOOTER;
            m_smtp.Send(m);
        }
        catch (Exception e)
        {
            throw e;
        }
    }
}
